#include "verilated.h"
#include "verilated_vcd_c.h"
#include "Vadder.h"

VerilatedContext* contextp = NULL;
VerilatedVcdC* tfp = NULL;

static Vadder* top;

void step_and_dump_wave(){
  top->eval();
  contextp->timeInc(1);
  tfp->dump(contextp->time());
}
void sim_init(){
  contextp = new VerilatedContext;
  tfp = new VerilatedVcdC;
  top = new Vadder;
  contextp->traceEverOn(true);
  top->trace(tfp, 0);
  tfp->open("waveform.vcd");
}

void sim_exit(){
  step_and_dump_wave();
  tfp->close();
}

int main() {
  sim_init();

  top->sel = 0b0;  top->a = 6; top->b = 1;  step_and_dump_wave(); // add
                   top->a = 7; top->b = 1;  step_and_dump_wave();
                   top->a = -7; top->b = 1;  step_and_dump_wave();
                   top->a = 0; top->b = 0;  step_and_dump_wave();
                   top->a = -8; top->b = -1;  step_and_dump_wave();
  top->sel = 0b1;  top->a = 6; top->b = 1;  step_and_dump_wave(); // sub
                   top->a = 7; top->b = -1;  step_and_dump_wave();
                   top->a = -7; top->b = 1;  step_and_dump_wave();
                   top->a = -8; top->b = 1;  step_and_dump_wave();
                   top->a = 6; top->b = 7;  step_and_dump_wave();
                   top->a = 0; top->b = 7;  step_and_dump_wave();
  sim_exit();
}
